package com.ruoyi.ly.utils;

import org.apache.http.HttpResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName SMSUtil
 * @Description TODO
 * @Author libowen
 * @Date 2025年05月12日 16:04
 * @Version 1.0
 */
public class SMSUtil {
    public static void send(String phone,String code) {
        // 发送短信的主机网址
        String host = "https://gyyyx1.market.alicloudapi.com";
        // 发送短信的路径
        String path = "/sms/smsSend";
        // 发送短信的请求方式
        String method = "POST";
        // 发送短信的appcode
        String appcode = "7f33f7d6df4b42c981ea146081d6ef0d";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        // 发送短信的参数
        querys.put("mobile", phone);
        querys.put("param", "**code**:"+code+",**minute**:5");

//smsSignId（短信前缀）和templateId（短信模板），可登录国阳云控制台自助申请。参考文档：http://help.guoyangyun.com/Problem/Qm.html

        querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
        querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad");
        Map<String, String> bodys = new HashMap<String, String>();

        try {
            HttpResponse response =  HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
